package com.zhubjiept.app.jinrirong.activity.user;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.zhubjiept.app.common.base.BasePresenter;
import com.zhubjiept.app.jinrirong.config.Constants;
import com.zhubjiept.app.jinrirong.config.RetrofitHelper;

import io.reactivex.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by wangsy on 2019/1/20.
 */

class TeamMemberRequestPresenter extends BasePresenter<TeamMemberView> {

    public void requestMyTeamInfo(String token, int type) {
        mView.showLoadingView();
        JSONObject requestData = new JSONObject();
        try {
            requestData.put("client", Constants.CLIENT);
            requestData.put("package", Constants.PACKAGE);
            requestData.put("ver", Constants.VER);
            requestData.put("token", token);
            requestData.put("type", type);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), requestData.toString());
        addTask(RetrofitHelper.getInstance().getService().myTeam(requestBody), new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                System.out.println("请求我的团队 返回：" + s);
                JSONObject result = (JSONObject) JSONObject.parse(s);
                JSONArray list = result.getJSONArray("data");
                getView().onRemoteSucceed(list);
                mView.hideLoadingView();
            }
        });
    }

}
